# MY OWN SETTINGS
# source $ZSH/oh-my-zsh.sh
#  History
#
# хранить историю в указанном файле
export HISTFILE=~/.term_history
# Игнорируются команды начинающиеся с пробела
export HISTCONTROL=$HISTCONTROL:ignorespace
# максимальное число команд, хранимых в сеансе
export HISTSIZE=50000
export SAVEHIST=$HISTSIZE
# включить историю команд
setopt APPEND_HISTORY
# убрать повторяющиеся команды, пустые строки и пр.
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_REDUCE_BLANKS

# Вытянуть из бинарника шеллкод
objdumptoshellcode (){
    for i in $(objdump -d $1 -M intel | grep "^ " | cut -f2); do 
        echo -En '\x'$i
    done
    echo 
}

# Запаковать архив
# example: pk tar file
pk () {
 if [ $1 ] ; then
 case $1 in
 tbz)       tar cjvf $2.tar.bz2 $2      ;;
 tgz)       tar czvf $2.tar.gz  $2       ;;
 tar)      tar cpvf $2.tar  $2       ;;
 bz2)    bzip $2 ;;
 gz)        gzip -c -9 -n $2 > $2.gz ;;
 zip)       zip -r $2.zip $2   ;;
 7z)        7z a $2.7z $2    ;;
 *)         echo "'$1' cannot be packed via pk()" ;;
 esac
 else
 echo "'$1' is not a valid file"
 fi

}
# Распаковка архивов
# example: extract file
unpk () {
 if [ -f $1 ] ; then case $1 in
 *.tar.bz2)   tar xjf $1        ;;
 *.tar.gz)    tar xzf $1     ;;
 *.bz2)       bunzip2 $1       ;;
 *.rar)       unrar x $1     ;;
 *.gz)        gunzip $1     ;;
 *.tar)       tar xf $1        ;;
 *.tbz2)      tar xjf $1      ;;
 *.tbz)       tar -xjvf $1    ;;
 *.tgz)       tar xzf $1       ;;
 *.zip)       unzip $1     ;;
 *.Z)         uncompress $1  ;;
 *.7z)        7z x $1    ;;
 *)           echo "I don't know how to extract '$1'..." ;;
 esac
 else
 echo "'$1' is not a valid file"
 fi
}

# ----------------------
# autoload -U compinit promptinit
autoload -Uz compinit ; compinit
autoload -Uz promptinit; promptinit



setopt autocd

autoload -U pick-web-browser
alias -s {html,htm}=firefox
alias -s {py,js}=nvim
alias rm='rm -i'
alias ls='ls --color=always'
alias lr='ls --color=always -lAR'
alias lg='ls --color=always -lA | grep -i'
alias zshrc='nvim ~/.zshrc'
alias vim='nvim'
alias cheet='curl cht.sh'
alias h='htop'
alias journalctl='sudo journalctl'
alias agent='eval $(ssh-agent -s) && ssh-add'
alias nc='ncat'
alias piprq='pip install -r requirements.txt'

alias son='sudo systemctl suspend'
alias fucked-screen='sudo systemctl restart display-manager'

alias pc4='proxychains4 -q'


# Path to your oh-my-zsh installation.
export ZSH="/home/katok/.oh-my-zsh"

ZSH_THEME="af-magic"
# Theme with collapsed pwd:
# ZSH_THEME="powerlevel10k/powerlevel10k"

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
DISABLE_LS_COLORS="true"
export LS_COLORS="$LS_COLORS:ow=1;34:tw=1;34:"

# Uncomment the following line to disable auto-setting terminal title.
DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
HIST_STAMPS="dd.mm.yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
    git
    docker-compose
    docker
    safe-paste
    colored-man-pages
)


# User configuration
#
# TODO: fix according to theese example:
#           typeset -U path PATH
#           path=(~/.local/bin $path)
#           export PATH

PATH=:~/scripts/:$PATH:$HOME/.node/bin:/opt/cuda/bin/:/home/katok/.local/share/gem/ruby/3.0.0/bin
NODE_PATH="$HOME/.node/lib/node_modules:$NODE_PATH"

export MANPATH="/usr/local/man:$HOME/.node/share/man:$MANPATH"
export GOPATH="$HOME/go"
export PATH=$PATH:$GOPATH/bin:/usr/bin
PATH="/home/katok/perl5/bin${PATH:+:${PATH}}"; export PATH;

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
  export EDITOR='vim'
else
  export EDITOR='nvim'
fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
alias zshconfig="nvim ~/.zshrc"
alias vimrc="nvim ~/.vimrc"
alias ohmyzsh="nvim ~/.oh-my-zsh"
alias gdb="gdb -q"
alias cls="clear"



# ----------------------------------------


PERL5LIB="/home/katok/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/katok/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/katok/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/katok/perl5"; export PERL_MM_OPT;


# PYENV

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

# Turning on autocompletion
zstyle ':completion:*:*:cp:*' file-sort size
zstyle ':completion:*' file-sort modification

zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'       # Case insensitive tab completion
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"         # Colored completion (different colors for dirs/files/etc)
zstyle ':completion:*' rehash true                              # automatically find new executables in path 
# Speed up completions
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache

# Use backgroud completion 

# while IFS= read -r script
# do
#     source "$script"
# done < <(find /usr/share/zsh/plugins/ -maxdepth 2 -type f -name "*.zsh" ! -name '*plugin.zsh')

source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source $ZSH/oh-my-zsh.sh


# set PROMPT
PS1='$FG[237]${(l.$(afmagic_dashes)..-.)}%{$reset_color%}
$FG[032]%3~$(git_prompt_info)$(hg_prompt_info) $FG[105]%(!.#.»)%{$reset_color%} '

# export ZSH_THEME_GIT_PROMPT_PREFIX=" %F{106}"
# ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
# ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[white]$bg[red]%}✖%{$reset_color%}%F{108}"
# ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}✔%{$reset_color%}%F{108}"

# export PS1='%F{241}$(rvm-prompt)%F{009}⎬%{$fg_bold[green]%}%p %F{172}%c%F{161}$(git_prompt_info)%{$fg_bold[blue]%} ❯ %{$reset_color%}'
